-
-
Notifications
You must be signed in to change notification settings - Fork 6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create a subclass of NSCache using a weak cache. #2228
Create a subclass of NSCache using a weak cache. #2228
Conversation
564e6da
to
2107e7e
Compare
…e when memory warning and sync back the alive instance from weak cache into cache.
2107e7e
to
216dfeb
Compare
Codecov Report
@@ Coverage Diff @@
## master #2228 +/- ##
=========================================
- Coverage 78.42% 78.4% -0.02%
=========================================
Files 36 36
Lines 3685 3733 +48
Branches 340 341 +1
=========================================
+ Hits 2890 2927 +37
- Misses 772 783 +11
Partials 23 23
Continue to review full report at Codecov.
|
@@ -26,7 +26,7 @@ - (SDOperationsDictionary *)sd_operationDictionary { | |||
if (operations) { | |||
return operations; | |||
} | |||
operations = [[NSMapTable alloc] initWithKeyOptions:NSMapTableCopyIn valueOptions:NSMapTableWeakMemory capacity:0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Acutally copy is useless. Because we always pass a immutable NSString
but not NSMutableString
. Use strong-weak is OK.
Nice @dreampiggy |
Only remove the cache when memory warning and sync back the alive instance from weak cache into cache.
New Pull Request Checklist
I have read and understood the CONTRIBUTING guide
I have read the Documentation
I have searched for a similar pull request in the project and found none
I have updated this branch with the latest master to avoid conflicts (via merge from master or rebase)
I have added the required tests to prove the fix/feature I am adding
I have updated the documentation (if necessary)
I have run the tests and they pass
I have run the lint and it passes (
pod lib lint
)This merge request fixes / reffers to the following issues: #791 #2227
Pull Request Description
See the description in #791. We can add a weak cache into memory cache for a little performance improvement on iOS/tvOS.
This is useful when the memory warning, the cache was purged. However, the image instance can be retained by other instance such as imageViews and alive. At this case, we can sync weak cache back and do not need to load from disk cache.
For example, you are showing a big imageView with a image, and a tableView contains the thumb image(Through the
UIImage
instance is the same one, only size and scale onUIImageView
different). When memory warning and cache purged, you can also directlly get the image from weak cache without async query disk or re-download.For other normal manually access method such as
removeObjectForKey:
,removeAllObjects
, we should also remove that weak cache to sync the state.